#!/usr/bin/ruby
require 'rubygems'
require 'date'
require 'historicalquote.rb'
require 'xmlparse.rb'

unless (ARGV.length > 1)
  puts "Usage: updatehistorical.rb <numberofdays - optional, 7 is the default>"
end

interval = 7
if (ARGV.length > 0)
  interval = ARGV[0].to_i
end

x = XmlParse.new("config.xml")
p = x.getparams()
hostname = p["hostname"]
user = p["user"]
pass = p["pass"]
dbname = p["dbname"]
  

sd = (Date.today. - interval).strftime("%m-%d-%y")

ex = ["NASDAQ", "NYSE"]
ex.each do |exchange|
  quotes = HistoricalQuote.new(hostname, user, pass, dbname)
  puts "Loading historical data for exchange #{exchange}..."
  quotes.loadhistoricaldata(sd.to_s, exchange)
  quotes.close
end

